package com.sinogrand.elevator.data.models

import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import kotlinx.parcelize.RawValue

/**
 * 通用API响应模型
 */
data class ApiResponse<T>(
    val code: Int,
    val data: T?,
    val msg: String
)

/**
 * 分页信息模型
 */
data class PageInfo(
    val page: Int,
    val size: Int,
    val total: Int
)

/**
 * 登录响应数据
 */
data class LoginResponse(
    val access_token: String,
    val user_info: UserInfo
)

/**
 * 用户信息模型
 */
data class UserInfo(
    val id: Int,
    val mobile: Long,
    val openid: String?,
    val avatar: String?,
    val real_name: String?,
    val id_card_no: String?,
    val signature: String?,
    val role_info: RoleInfo,
    val dept_info: DeptInfo,
    val has_valid_project: Boolean,
    val template_list: Map<String, Int>?
)

/**
 * 角色信息模型
 */
data class RoleInfo(
    val id: Int,
    val name: String,
    val code: String
)

/**
 * 部门信息模型
 */
data class DeptInfo(
    val id: Int,
    val name: String
)


/**
 * 电梯列表响应数据
 */
data class ElevatorListResponse(
    val list: List<ElevatorItem>,
    val page_info: PageInfo
)

/**
 * 电梯项数据模型 - 统一模型，支持所有API字段
 */
@Parcelize
data class ElevatorItem(
    val id: Int,
    val name: String,
    val no: String,
    val sn: String?,
    val type: Int?,
    val install_type: String?,
    val brand: String?,
    val model: String?,
    val floors: Int?,
    val unit_price: Double?,
    val start_date: String?,
    val end_date: String?,
    val details: String?,
    val status: Int,
    val approval_config: String?,
    val has_filing: Boolean?,
    val has_monitoring: Boolean?,
    val created_at: String?,
    val updated_at: String?,
    val imageUrl: String? = null // UI显示用的图片字段
) : Parcelable


/**
 * 项目列表响应数据
 */
data class ProjectListResponse(
    val list: List<ProjectItem>,
    val page_info: PageInfo
)

/**
 * 项目项数据模型
 */
@Parcelize
data class ProjectItem(
    val id: Int,
    val type: Int,                   // 项目类型
    val name: String,                // 项目名称
    val address: String,             // 项目地址
    val elevator_count: Int,         // 电梯数量
    val details: @RawValue Any?,     // 项目详情
    val status: Int,                 // 项目状态
    val created_at: String,          // 创建时间
    val updated_at: String           // 更新时间
) : Parcelable

/**
 * 首页电梯列表响应数据
 */
data class HomeElevatorListResponse(
    val list: List<HomeElevatorItem>,
    val page_info: PageInfo
)

/**
 * 项目用户列表响应数据
 */
data class ProjectUserListResponse(
    val list: List<ProjectUserItem>,
    val page_info: PageInfo
)

/**
 * 项目用户项数据模型
 */
@Parcelize
data class ProjectUserItem(
    val id: Int,
    val user_id: Int,
    val real_name: String,
    val mobile: String,
    val avatar: String?,
    val id_card_no: String?,
    val role_id: Int,
    val role_name: String,
    val certificate_data: CertificateData?,
    val status: Int,
    val created_at: String,
    val updated_at: String
) : Parcelable

/**
 * 证书数据模型
 */
@Parcelize
data class CertificateData(
    val id_card_front: String?,
    val id_card_back: String?,
    val insurance: String?,
    val insurance_start: String?,
    val insurance_end: String?,
    val certificate_special_equipment: String?,
    val certificate_electrician: String?,
    val certificate_welder_cutting: String?,
    val certificate_high_altitude_work: String?,
    val certificate_safety_officer: String?,
    val certificate_quality_inspector: String?,
    val certificate_scaffolder: String?
) : Parcelable

/**
 * 首页电梯项数据模型
 */
@Parcelize
data class HomeElevatorItem(
    val id: Int,
    val name: String,
    val type: Int,
    val install_type: String,
    val start_date: String,
    val end_date: String,
    val status: Int,
    val created_at: String,
    val updated_at: String
) : Parcelable

// 待办事项相关数据模型
data class TodoListResponse(
    val list: List<TodoItem>,
    val page_info: PageInfo
)

@Parcelize
data class TodoItem(
    val id: Int,
    val type: Int,
    val title: String,
    val form_id: Int,
    val record_id: Int,
    val created_at: String,
    val updated_at: String
) : Parcelable

/**
 * 电梯详情响应数据
 */
data class ElevatorDetailData(
    val info: ElevatorDetailInfo
)

/**
 * 电梯详情信息模型
 */
@Parcelize
data class ElevatorDetailInfo(
    val id: Int,
    val project_id: Int,
    val name: String,
    val no: String,
    val sn: String,
    val type: Int,
    val install_type: String,
    val brand: String,
    val model: String,
    val floors: Int,
    val unit_price: Double,
    val start_date: String,
    val end_date: String,
    val details: List<ElevatorDetailItem>,
    val status: Int,
    val approval_config: ApprovalConfig,
    val stage_data: StageData,
    val has_filing: Boolean,
    val has_monitoring: Boolean,
    val check_inspection: Boolean,
    val check_overdue: Boolean,
    val product_config_table: List<String>,
    val created_at: String,
    val updated_at: String
) : Parcelable

/**
 * 电梯详情项模型
 */
@Parcelize
data class ElevatorDetailItem(
    val code: String,
    val name: String,
    val value: String
) : Parcelable

/**
 * 审批配置模型
 */
@Parcelize
data class ApprovalConfig(
    val protection: Int,
    val lofting: Int,
    val lofting_payment: Int,
    val slow_car_debugging: Int,
    val slow_car_debugging_payment: Int,
    val track_door_installation: Int,
    val track_door_installation_payment: Int,
    val fast_car_debugging: Int,
    val fast_car_debugging_payment: Int,
    val acceptance: Int,
    val acceptance_payment: Int,
    val transfer: Int,
    val transfer_payment: Int,
    val arrival: Int,
    val unpacking: Int
) : Parcelable

/**
 * 阶段数据模型
 */
@Parcelize
data class StageData(
    val stage_1_ratio: Int,
    val stage_1_amount: Int,
    val stage_1_status: Boolean,
    val stage_2_ratio: Int,
    val stage_2_amount: Int,
    val stage_2_status: Boolean,
    val stage_3_ratio: Int,
    val stage_3_amount: Int,
    val stage_3_status: Boolean,
    val stage_4_ratio: Int,
    val stage_4_amount: Int,
    val stage_4_status: Boolean,
    val stage_5_ratio: Int,
    val stage_5_amount: Int,
    val stage_5_status: Boolean,
    val stage_6_ratio: Int,
    val stage_6_amount: Int,
    val stage_6_status: Boolean
) : Parcelable

/**
 * 电梯日志列表响应数据
 */
data class ElevatorLogListResponse(
    val list: List<ElevatorLogItem>,
    val page_info: PageInfo
)

/**
 * 电梯日志项数据模型
 */
@Parcelize
data class ElevatorLogItem(
    val id: Int,
    val type: Int,
    val content: String,
    val form_id: Int,
    val user_name: String,
    val created_at: String,
    val updated_at: String
) : Parcelable

/**
 * 我的审批列表响应数据
 */
data class MyApprovalListResponse(
    val list: List<MyApprovalItem>,
    val page_info: PageInfo
)

/**
 * 我的审批项数据模型
 */
@Parcelize
data class MyApprovalItem(
    val id: Int,
    val title: String,
    val description: String,
    val form_id: Int,
    val record_id: Int,
    val created_at: String,
    val updated_at: String
) : Parcelable

/**
 * 个人信息响应数据
 */
data class ProfileInfoResponse(
    val info: ProfileInfo
)

/**
 * 个人信息数据模型
 */
data class ProfileInfo(
    val id: Int,
    val mobile: Long,
    val openid: String?,
    val avatar: String?,
    val real_name: String?,
    val id_card_no: String?,
    val signature: String?,
    val role_info: RoleInfo,
    val dept_info: DeptInfo?,
    val has_valid_project: Boolean,
    val template_list: Map<String, Int>?
)

/**
 * 审批记录列表响应数据
 */
data class ApprovalRecordListResponse(
    val list: List<ApprovalRecordItem>,
    val page_info: PageInfo
)

/**
 * 审批记录项数据模型
 */
@Parcelize
data class ApprovalRecordItem(
    val id: Int,
    val form_id: Int,
    val template_id: Int,
    val template_name: String,
    val project_id: Int,
    val project_name: String,
    val title: String
) : Parcelable
